home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / cli-common / runtimes.d / mono
Encoding:
Text File  |  2007-02-27  |  3.2 KB  |  147 lines

  1. #!/usr/bin/perl
  2.  
  3. #
  4. # Setup
  5. #
  6.  
  7. # Directives
  8. use strict;
  9. use warnings;
  10.  
  11. # Modules
  12. use File::Basename;
  13.  
  14. # Figure out the mode
  15. my $mode = shift @ARGV;
  16.  
  17. if (!defined $mode)
  18. {
  19.     print STDERR "E: You must supply a mode\n";
  20.     print STDERR "E: Use: install, remove, or name\n";
  21.     exit 1;
  22. }
  23.  
  24. # Name is simply
  25. if ($mode eq "name")
  26. {
  27.     print "Mono\n";
  28.     exit 0;
  29. }
  30.  
  31. # This program gets the name of a file (ending in .installcligac) and
  32. # a list of assemblies to install, as full paths. The ones given are
  33. # the only ones that passed the white/blacklisting.
  34.  
  35. # Get the base file
  36. my $basename = shift @ARGV;
  37. my $cligac = "/usr/share/cli-common/packages.d/$basename.installcligac";
  38.  
  39. if (! -f $cligac)
  40. {
  41.     print STDERR "E: File does not exist: $cligac\n";
  42.     exit 1;
  43. }
  44.  
  45. # Get the base directory
  46. my $basedir = "/usr/share/cli-common/packages.d/";
  47.  
  48. # Removing is also simple
  49. if ($mode eq "remove")
  50. {
  51.     # Get the uninstall file
  52.     my $uninstall = "$basedir/$basename.mono";
  53.  
  54.     if (-f $uninstall)
  55.     {
  56.     # Go through the file
  57.     open UNINSTALL, "<$uninstall" or
  58.         die "E: Cannot open uninstall file ($!)";
  59.  
  60.     while (<UNINSTALL>)
  61.     {
  62.         # Clean up the line and get the base directory
  63.         chomp;
  64.          my $cmd = "/usr/bin/mono /usr/lib/mono/1.0/gacutil.exe /u $_"
  65.          . " > /dev/null";
  66.          system($cmd) == 0 or
  67.              print STDERR "W: removing Assembly $_ failed!\n";
  68.     }
  69.  
  70.     close UNINSTALL;
  71.  
  72.     # Unlike the file
  73.     unlink($uninstall);
  74.     }
  75.  
  76.     # We are good
  77.     exit 0;
  78. }
  79.  
  80. # The only thing left should be "install"
  81. if ($mode ne "install")
  82. {
  83.     print STDERR "E: Unknown mode: $mode\n";
  84.     print STDERR "E: Use: install, remove, or name\n";
  85.     exit 1;
  86. }
  87.  
  88.  
  89. # Open up our uninstall file
  90. open UNINSTALL, ">$basedir/$basename.mono"
  91.     or die "E: Cannot open uninstall: $basedir/$basename.mono";
  92.  
  93. # Go through the file
  94. open CLIGAC, "<$cligac" or die "E: Cannot open: $cligac ($!)";
  95.  
  96. while (@ARGV)
  97. {
  98.     # Get the assembly name
  99.     my $dll = shift @ARGV;
  100.     
  101.     # Make sure it is there
  102.     if (! -f $dll)
  103.     {
  104.     print STDERR "E: Assembly does not exist: $dll\n";
  105.     exit 1;
  106.     }
  107.     
  108.     # Figure out the mono's precise name
  109.     my $fullname = get_full_name($dll);
  110.     
  111.     # Write out the uninstall file
  112.     print UNINSTALL "$fullname\n";
  113.     
  114.     # Install the file. We use the "../../../.." to make it a
  115.     # relative path to this program (since gacutil doesn't like
  116.     # absolute paths). There isn't a problem of doing too many
  117.     # since we typically run from the root context.
  118.     my $cmd = "(cd `dirname $dll` && "
  119.         . "/usr/bin/mono /usr/lib/mono/1.0/gacutil.exe /i `basename $dll`"
  120.        . " > /dev/null)";
  121.     system($cmd) == 0 or die "E: installing Assembly $dll failed\n";
  122. }
  123.  
  124. close CLIGAC;
  125. close UNINSTALL;
  126.  
  127. # Finish up successfully
  128. exit 0;
  129.  
  130. # Get the name of the assembly in a manner suitable for uninstall
  131. # using gacutil.
  132. sub get_full_name
  133. {
  134.     # Get the name
  135.     my $dll = shift;
  136.  
  137.     # Open a pipe to monop
  138.     my $cmd = "LANG=C /usr/bin/mono /usr/share/mono/MonoGetAssemblyName.exe $dll";
  139.     open PIPE, "$cmd |" or die "E: Cannot open pipe to assembly builder $dll";
  140.  
  141.     # This generate a single line that produces the desired results
  142.     $_ = <PIPE>;
  143.     chomp;
  144.      # assembly1, Version=1.0.0.0, Culture=en, PublicKeyToken=0123456789abcdef
  145.     return $_;
  146. }
  147.